using System.Security.Cryptography.X509Certificates;

namespace WebSMS;

[Route("[controller]/[action]")]
[Controller]
public class SystemController
{
    private readonly UserService _userService;
    private readonly PostService _postService;
    private readonly DepartmentService _departmentService;
    private readonly IRepository<DataPo> _repositoryData;
    
    public SystemController(UserService userService,
        PostService postService,
        DepartmentService departmentDervice,
        IRepository<DataPo> repositoryData)
    {
        _userService = userService;
        _postService = postService;
        _departmentService = departmentDervice;
        _repositoryData = repositoryData;
    }
    
    [HttpGet]
    public ResponseObject<SystemDataInfo> SystemInfo()
    {
        var userContent = _userService.GetUserCount() ;
        var postContent = _postService.GetPostCount();
        var departmentContent = _departmentService.GetDepartmentCount();
        SystemDataInfo dataInfo = new SystemDataInfo() {
            DepartNumber = departmentContent, 
            PotsNumber = postContent,
            UserNumber = userContent
        };
        return new ResponseObject<SystemDataInfo>().Ok(dataInfo);
    }

    [HttpGet]
    public ResponseObject<IQueryable> GetCreateDateGroup()
    {
        var group = _userService.GetUserGroupByCreateDate();
        return new ResponseObject<IQueryable>().Ok(group);
    }

    [HttpGet]
    public ResponseObject<IQueryable> GetBanDateGroup()
    {
        var group = _userService.GetUserGroupByBanDate();
        return new ResponseObject<IQueryable>().Ok(group);
    }

    [HttpGet]
    public ResponseObject<IQueryable> GetDelDateGroup()
    {
        var group = _userService.GetUserGroupByDelDate();
        return new ResponseObject<IQueryable>().Ok(group);
    }

    [HttpGet]
    [Authorize]
    public ResponseObject<IQueryable<DataPo>> GetDataList()
    {
        return new ResponseObject<IQueryable<DataPo>>().Ok(_repositoryData.AsQueryable(),"查询成功！");
    }

    // [HttpPost]
    // [Authorize]
    // public ResponseObject<Object> UploadAvatar(HttpContext httpContext)
    // {
    //     // 获取上传的图片
    //    var file =  HttpContext.Request.Form.Files[0];
    //     return new ResponseObject<Object>().Ok("");
    // }
}

public class SystemDataInfo
{
    public int UserNumber { get; set; }
    public int DepartNumber{ get; set; }
    public int PotsNumber{ get; set; }
}